home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / ghostscr / gs252ini.zip / GS_2ASC.PS < prev    next >
Text File  |  1992-07-26  |  6KB  |  177 lines

  1. %    Copyright (C) 1991, 1992 Aladdin Enterprises.  All rights reserved.
  2. %    Distributed by Free Software Foundation, Inc.
  3. %
  4. % This file is part of Ghostscript.
  5. %
  6. % Ghostscript is distributed in the hope that it will be useful, but
  7. % WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. % to anyone for the consequences of using it or for whether it serves any
  9. % particular purpose or works at all, unless he says so in writing.  Refer
  10. % to the Ghostscript General Public License for full details.
  11. %
  12. % Everyone is granted permission to copy, modify and redistribute
  13. % Ghostscript, but only under the conditions described in the Ghostscript
  14. % General Public License.  A copy of this license is supposed to have been
  15. % given to you along with Ghostscript so you can know your rights and
  16. % responsibilities.  It should be in a file named COPYING.  Among other
  17. % things, the copyright notice and this notice must be preserved on all
  18. % copies.
  19.  
  20. % Extract the ASCII text from a PostScript file.  Nothing is displayed.
  21. % Instead, lines are written to stdout as follows:
  22. %    F <height> <width> (<fontname>)
  23. %        indicate font height and width of a space
  24. %    S <x> <y> (<string>) <width>
  25. %        display a string
  26. %    P
  27. %        end of page
  28. % <height> is an integer expressed in tenths of a point
  29. % <width> is an integer in tenths of a point.
  30. % <x> and <y> are integer coordinates, in tenths of a point, with origin
  31. %   at lower left.
  32. % <string> and <fontname> are string represented with the standard
  33. %   PostScript escape conventions.
  34. % The idea is similar to Glenn Reid's `distillery', only a lot more
  35. % simple-minded, and less robust.
  36.  
  37. % Note that this code will only work properly if systemdict is writable
  38. % and if `binding' the definitions of operators defined as procedures
  39. % is deferred.  For this reason, it is normally invoked with
  40. %    gs -q -dNOBIND -dWRITESYSTEMDICT gs_2asc.ps
  41.  
  42. % Thanks to J Greely <jgreely@cis.ohio-state.edu> for improvements
  43. % to this code.
  44.  
  45. /QUIET true def
  46. systemdict wcheck { systemdict } { userdict } ifelse begin
  47.  
  48. % Disable the display operators.
  49.  
  50. /eofill { newpath } odef
  51. /erasepage { } odef
  52. /fill { newpath } odef
  53. /stroke { newpath } odef
  54.  
  55. % The image operators must read the input, but do nothing.
  56.  
  57. /colorimage { gsave nulldevice //colorimage grestore } odef
  58. /image { gsave nulldevice //image grestore } odef
  59. /imagemask { gsave nulldevice //imagemask grestore } odef
  60.  
  61. % Redefine the end-of-page operators.
  62.  
  63. /copypage { (P\n) //print } odef
  64. /showpage { copypage erasepage initgraphics } odef
  65.  
  66. % Redefine `show'.
  67.  
  68. % Set things up so our output will be in tenths of a point, with origin at
  69. % lower left.  This isolates us from the peculiarities of individual devices.
  70. /.show.ident.matrix matrix def
  71. /.show.ident
  72.  { gsave initmatrix 0.1 dup scale .show.ident.matrix currentmatrix grestore
  73.  } def
  74. /.coord { transform .show.ident itransform } odef
  75. /.dcoord { dtransform .show.ident idtransform } odef
  76. /.showfont
  77. %old code - This didn't work right for me with all fonts.
  78. %
  79. % { 0 currentfont /FontBBox get dup 3 get exch 1 get sub
  80. %   currentfont /FontMatrix get dtransform dtransform
  81. %   exch abs exch abs max round
  82. %   (F ) //print //.stdout exch write==only (\n) //print
  83. % } odef
  84. %
  85. %unfortunately, my way bombs on one of my test files in
  86. %--%show_continue--(?!).  It's from dvi2ps, which molests
  87. %the fonts in some way. --jgreely
  88.  { (F ) //print
  89.    gsave
  90.      % figure out (roughly) the maximum height of the current
  91.      % font.  I picked this string for a mix of ascenders and
  92.      % descenders, with digits tossed in in case of oldstyle
  93.      newpath 0 0 moveto
  94.      (Xyhq69) false charpath flattenpath pathbbox newpath
  95.      exch 4 -1 roll sub 3 1 roll exch sub .dcoord
  96.      round abs //.stdout exch write==only pop
  97.      ( ) //print
  98.      % oddly enough, the "charpath...pathbbox" stuff didn't work
  99.      % right for space in courier
  100.      ( ) stringwidth
  101.      .dcoord pop
  102.      round //.stdout exch write==only
  103. %     ( ) //print
  104. %     //.stdout currentfont /FontName get
  105. %     dup type /nametype eq { =string cvs } if
  106. %     write==only
  107.      (\n) //print
  108.    grestore
  109.  } odef
  110.  
  111. /.showstring
  112.  { (S ) //print
  113.    gsave
  114.      currentpoint .coord
  115.      exch round dup //.stdout exch write==only
  116.      ( ) //print
  117.      exch round dup //.stdout exch write==only
  118.      ( ) //print
  119.      moveto dup //.stdout exch write==only
  120.      ( ) //print
  121.    grestore dup stringwidth pop 0 rmoveto
  122.    stringwidth .dcoord pop
  123.    round //.stdout exch write==only
  124.    (\n) //print
  125.  } odef
  126.      
  127. /show
  128.  { .showfont .showstring
  129.  } odef
  130.  
  131. % Redefine the other string display operators in terms of `show'.
  132.  
  133. /.show1 { ( ) dup 0 3 index put exch pop .showstring } odef
  134. /ashow
  135.  { .showfont
  136.    { .show1 2 copy rmoveto } forall
  137.    exch neg exch neg rmoveto
  138.  } odef
  139. /widthshow
  140.  { .showfont
  141.    { 2 copy .show1 eq { 1 index 2 index rmoveto } if } forall
  142.    pop pop pop
  143.  } odef
  144. /awidthshow
  145.  { .showfont
  146.    { dup .show1 3 index eq { 4 index 5 index rmoveto } if
  147.      2 copy rmoveto
  148.    } forall
  149.    exch neg exch neg rmoveto
  150.    pop pop pop
  151.  } odef
  152. /kshow
  153.  { .showfont
  154.    { .show1 dup exec } forall pop
  155.  } odef
  156.  
  157. % Redirect the printing operators.
  158.  
  159. /.stdout (_temp_.out) (w) file def
  160. /.stderr (_temp_.err) (w) file def
  161. /print { //.stdout exch writestring } odef
  162.  
  163. end
  164.  
  165. % Bind the operators we just defined, and all the others if we didn't
  166. % do it before.
  167.  
  168. bindoperators
  169. NOBIND currentdict systemdict ne and
  170.  { systemdict begin bindoperators end }
  171. if
  172.  
  173. % Make systemdict read-only if it wasn't already.
  174.  
  175. systemdict wcheck { systemdict readonly pop } if
  176.